package com.hejielife.worker;

import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentLinkedQueue;

/**
 * 2019年8月1日 下午4:17:16
 * 
 * @author hejielife
 * @despribe 处理任务的工人
 */
public class Worker implements Runnable {

	private ConcurrentLinkedQueue<Task> workQueue;
	private ConcurrentHashMap<String, Object> resultMap;

	public void setWorkerQueue(ConcurrentLinkedQueue<Task> workQueue) {
		this.workQueue = workQueue;
	}

	public void setResultMap(ConcurrentHashMap<String, Object> resultMap) {
		this.resultMap = resultMap;
	}

	public void run() {
		while (true) {
			Task input = this.workQueue.poll();
			if (input == null)
				break;
			// 真正的去做业务处理
			Object output = MyWorker.handle(input);
			this.resultMap.put(Integer.toString(input.getId()), output);
		}
	}

	public static Object handle(Task input) {
		return null;
	}

}
